package com.jp.knowledge.activity;

import android.content.Context;
import android.content.Intent;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;

import com.dmcc.image_preview.ImagePreviewActivity;
import com.jp.knowledge.R;
import com.jp.knowledge.model.DocBean;

import java.util.ArrayList;

/**
 * Created by 528787067@qq.com on 2017/1/11.
 */

public class OpenDocActivity extends ImagePreviewActivity {

    public static void startActivity(Context mContext, int position, ArrayList<String> extraPics, DocBean doc) {
        if(position < 0 || position >= extraPics.size()) {
            return;
        }
        Intent intent = new Intent(mContext, OpenDocActivity.class);
        intent.putExtra("position", position);
        intent.putExtra("extraPics", extraPics);
        intent.putExtra("doc",doc);
        mContext.startActivity(intent);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.read_doc_menu, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();
        if (id == R.id.save) {
            savePicture();
        } else if(id == R.id.open){
            startActivity(getIntent().setClass(this, ReadDocActivity.class));
        } else if (id == android.R.id.home){
            finish();
        }
        return true;
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if(keyCode == KeyEvent.KEYCODE_MENU)
            return true;
        return super.onKeyDown(keyCode, event);
    }
}
